﻿#ifndef DAAPPRIBBONAREA_H
#define DAAPPRIBBONAREA_H
#include <QObject>
#include <QAction>
#include <QUndoStack>
#include "DAAppRibbonAreaInterface.h"
#include "numpy/DAPyDType.h"
namespace Ui
{
class AppMainWindow;
}
// Qt-Advanced-Docking-System 前置申明
namespace ads
{
class CDockWidget;
}
class QComboBox;
class SARibbonBar;
class SARibbonCategory;
class SARibbonPannel;
class SARibbonContextCategory;
class SARibbonLineWidgetContainer;
class SARibbonButtonGroupWidget;

namespace DA
{
class AppMainWindow;
class DAAppDockingArea;
class DAPyDTypeComboBox;
class DACommandInterface;
class DADataOperateOfDataFrameWidget;
class DAProject;
/**
 * @brief App的Ribbon区域接口，负责ribbon层的管理和调度
 *
 * @todo 后续抽象出DAAppRibbonAreaInterface，DAAppRibbonArea继承DAAppRibbonAreaInterface，并把可暴露的方法暴露出来，实现插件化
 */
class DAAppRibbonArea : public DAAppRibbonAreaInterface
{
    friend class AppMainWindow;
    Q_OBJECT
public:
    DAAppRibbonArea(DAAppUIInterface* u);
    ~DAAppRibbonArea();

    //发生语言变更时会触发此函数
    virtual void retranslateUi() override;
    //获取app
    AppMainWindow* app() const;
    //获取ribbon
    SARibbonBar* ribbonBar() const;
    //获取主标签
    SARibbonCategory* getRibbonCategoryMain() const;
    //返回一个list，包含支持的文件[Images (*.png *.xpm *.jpg)] [Text files (*.txt)]
    QStringList getFileReadFilters() const;
    //设置dockarea的指针 note 注意这个要在构建完成后设置进去
    void setDockAreaInterface(DAAppDockingArea* d);
    //通过DACommandInterface构建redo/undo的action
    void buildRedoUndo(DACommandInterface* cmd);
    //获取当前dataframeOperateWidget,如果没有返回nullptr,此函数不返回nullptr的前提是
    DADataOperateOfDataFrameWidget* getCurrentDataFrameOperateWidget(bool checkDataOperateAreaFocused = true);
    //更新ActionLockBackgroundPixmap的check statue
    void updateActionLockBackgroundPixmapCheckStatue(bool c);
    //设置工程
    DAProject* getProject() const;
    void setProject(DAProject* project);

public:
    //设置DataFrame的类型，【Context】 - 【dataframe】 DataFrame -> Type -> Type,此函数的调用忽略combox的currentindexchanged信号
    void setDataframeOperateCurrentDType(const DAPyDType& d);

private:
    //构建所有的action
    void buildAction();
    //构建界面
    void buildRibbon();
    //构建主页
    void buildRibbonMainCategory();
    //构建数据标签
    void buildRibbonDataCategory();
    //构建主页
    void buildRibbonViewCategory();
    //构建主页
    void buildRibbonConfigCategory();
    //构建快速响应栏
    void buildRibbonQuickAccessBar();
    //构建DataFrame上下文标签
    void buildContextCategoryDataFrame();
    //初始化信号槽
    void initConnection();
    //初始化脚本信息
    void initScripts();
    //翻译redo/undo
    void retranslateRedoUndo();
private slots:

    //==========================================
    // Main Category
    //打开文件
    void onActionOpenTriggered();

    //==========================================
    // Data Category
    void onActionAddDataTriggered();
    void onActionRemoveRowTriggered();
    void onActionRemoveColumnTriggered();
    void onActionRemoveCellTriggered();
    void onActionInsertRowTriggered();
    void onActionInsertRowAboveTriggered();
    void onActionInsertColumnRightTriggered();
    void onActionInsertColumnLeftTriggered();
    void onActionRenameColumnsTriggered();
    void onActionCreateDataDescribeTriggered();
    void onComboxColumnTypesCurrentDTypeChanged(const DAPyDType& dt);
    void onActionCastToNumTriggered();
    void onActionCastToStringTriggered();
    void onActionCastToDatetimeTriggered();
    void onActionChangeToIndexTriggered();
    //==========================================
    // View Category
    //显示工作流/绘图/数据区域
    void onActionShowWorkFlowAreaTriggered();
    void onActionShowChartAreaTriggered();
    void onActionShowDataAreaTriggered();
    //显示信息区域
    void onActionShowMessageLogViewTriggered();
    //显示设置区域
    void onActionSettingWidgetTriggered();

    //==========================================
    // Config Category
    //插件管理对话框触发
    void onActionPluginManagerTriggered(bool on);

    //==========================================
    // Qt-Advanced-Docking-System
    // DockWidget的焦点变化
    void onFocusedDockWidgetChanged(ads::CDockWidget* old, ads::CDockWidget* now);

private:
    DAAppDockingArea* m_dockArea;  ///< 注意这个变量不能在构造函数中调用
    AppMainWindow* m_app;
    // main
    SARibbonCategory* m_categoryMain;     ///< 主页标签
    SARibbonPannel* m_pannelMainFileOpt;  ///< 文件操作
    SARibbonPannel* m_pannelMainDataOpt;  ///< 文件操作
    // data
    SARibbonCategory* m_categoryData;     ///< 数据标签
    SARibbonPannel* m_pannelDataOperate;  ///< 数据操作
    // view
    SARibbonCategory* m_categoryView;      ///< 视图标签
    SARibbonPannel* m_pannelViewMainView;  ///< 主要视图操作
    // Config
    SARibbonCategory* m_categoryConfig;  ///< 配置标签
    SARibbonPannel* m_pannelConfigMain;  ///< 主要配置操作
    // Context - dataframe
    SARibbonContextCategory* m_contextDataFrame;                ///< 对应dataframe的上下文
    SARibbonCategory* m_categoryDataframeOperate;               ///< dataframe对应的category
    SARibbonPannel* m_pannelDataframeOperateAxes;               ///< 数据信息的编辑
    SARibbonPannel* m_pannelDataframeOperateDType;              ///< 数据类型的编辑
    SARibbonLineWidgetContainer* m_comboxColumnTypesContainer;  ///<列类型选择器的container
    SARibbonButtonGroupWidget* m_castActionsButtonGroup;        ///< 管理强制转换的action的工具栏
    DAPyDTypeComboBox* m_comboxColumnTypes;                     ///< 列类型选择器
    SARibbonPannel* m_pannelDataframeOperateStatistic;          ///< 统计相关操作
    // Main Category
    QAction* m_actionOpen;
    QAction* m_actionSave;
    QAction* m_actionSaveAs;
    QAction* m_actionRedo;
    QAction* m_actionUndo;
    // Data Category
    QAction* m_actionAddData;
    QAction* m_actionRemoveRow;
    QAction* m_actionRemoveColumn;
    QAction* m_actionRemoveCell;  // 移除单元格（设置为nan）
    QAction* m_actionInsertRow;
    QAction* m_actionInsertRowAbove;
    QAction* m_actionInsertColumnLeft;   // 在左边插入列
    QAction* m_actionInsertColumnRight;  // 在右边插入列
    QAction* m_actionRenameColumns;
    QAction* m_actionCastToString;        //数据转换为文本
    QAction* m_actionCastToNum;           //数据转换为数字
    QAction* m_actionCastToDatetime;      //转换为日期
    QAction* m_actionCreateDataDescribe;  //数据描述
    QAction* m_actionChangeToIndex;       ///< 把某列转换为index
    QMenu* m_menuInsertRow;               ///< 针对insertrow的action menu
    QMenu* m_menuInsertColumn;            ///< 这对insertcol的action menu
    // View Category
    QAction* m_actionShowWorkFlowArea;
    QAction* m_actionShowChartArea;
    QAction* m_actionShowDataArea;
    QAction* m_actionShowMessageLogView;
    QAction* m_actionShowSettingWidget;
    // Config Category
    QAction* m_actionPluginManager;
    //
    QStringList m_fileReadFilters;
    //
    QUndoStack m_dataManagerStack;  ///< 数据管理的stack
};
}  // namespace DA
#endif  // DAAPPRIBBONAREA_H
